package com.hdey.service.heng.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdey.mapper.heng.TbUscPurchaseChildMapper;
import com.hdey.mapper.heng.TbUscPurchaseMasterMapper;
import com.hdey.pojo.heng.TbUscPurchaseMaster;
import com.hdey.service.heng.TbUscPurchaseMasterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service("tbUscPurchaseMasterService")
@Transactional
public class TbUscPurchaseMasterServiceImpl extends ServiceImpl<TbUscPurchaseMasterMapper,TbUscPurchaseMaster> implements TbUscPurchaseMasterService {

    @Resource
    private TbUscPurchaseMasterMapper masterMapper;


    @Override
    public Page<TbUscPurchaseMaster> showAll(Integer current,Integer size,String purchaseNo, String purchaseStatus, String supplyCode) {
        Page<TbUscPurchaseMaster> page=new Page<>(current,size);
        LambdaQueryWrapper<TbUscPurchaseMaster> wrapper=new LambdaQueryWrapper<>();

        if(purchaseNo!=null&&!"".equals(purchaseNo)&&!"null".equals(purchaseNo)){
            wrapper.like(TbUscPurchaseMaster::getPurchaseNo,purchaseNo);
        }
        if(purchaseStatus!=null&&!"".equals(purchaseStatus)&&!"null".equals(purchaseStatus)){
            wrapper.eq(TbUscPurchaseMaster::getPurchaseStatus,purchaseStatus);
        }
        if(supplyCode!=null&&!"".equals(supplyCode)){
            wrapper.like(TbUscPurchaseMaster::getSupplyCode,supplyCode);
        }
        masterMapper.selectPage(page, wrapper);
        return page;
    }

    @Override
    public int insert(TbUscPurchaseMaster master) {
        master.setCreateDate(LocalDate.now());
        master.setPurchaseDate(LocalDateTime.now());
        System.out.println("Service"+master);
        return masterMapper.insert(master);
    }

    @Override
    public int update(int masterId) {
        return masterMapper.update(masterId);
    }
}
